package yunquan.wang.base.web.taglib;

import java.io.IOException;
import java.util.Set;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import yunquan.wang.base.appcode.AppcodeHolder;
import yunquan.wang.modules.base.entity.CodeValue;

public class CodeRadioTaglib  extends TagSupport{
	private String type;// 码表类型
	private String name;// radio 框的名字
	private Object value;// 选中的值
	
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Object getValue() {
		return value;
	}
	public void setValue(Object value) {
		this.value = value;
	}
	public int doEndTag() throws JspException {
		JspWriter out = pageContext.getOut();
		StringBuffer sbf = new StringBuffer();
		Set<CodeValue> codeValues = AppcodeHolder.getAllCodeValue(type);
		for(CodeValue codeValue :codeValues)
		{
			//<label class="radioButton"><input name="name" type="radio" />全部</label>
			sbf.append("<label class=\"radioButton\"><input name=\""+name);
			sbf.append("\" type=\"radio\" " + " value=\""+codeValue.getCode()+"\"");
			if(value!=null&&codeValue.getCode().equals(value.toString()))
			{
				sbf.append(" checked ");
			}
			sbf.append("/>");
			sbf.append(codeValue.getValue());
			sbf.append("</label>");
		}
		try {
			out.print(sbf);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
